import{
    CHANGE_INPUT_VALUE,
    DELETE_TODO_ITEM,
    ADD_TOTO_ITEM,
    INIT_LIST_ACTION
} from './actionTypes'
import axios from 'axios';


export const getInputChangeAction = (value) => ({
    type: CHANGE_INPUT_VALUE,
    value
});


export const getAddItemAction = () => ({
    type: ADD_TOTO_ITEM,
});

export const getDeleteItemAction = (index) => ({
    type: DELETE_TODO_ITEM,
    index
});

export const initListAction = (data) => ({ // 返回的是一个对象，最外层的()代表return
    type: INIT_LIST_ACTION,
    data
});

export const getTodoList = () => {// 使用redux-thunk可以返回一个函数了
    return (dispatch) => {
        axios.get('/list.json').then((res)=>{
            const data = res.data;
            const action = initListAction(data);
            dispatch(action)
        })
    }
}

